package com.spcloud.fegin;

import com.netflix.loadbalancer.BestAvailableRule;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.spcloud.fegin.fegin.OrderService;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author GuoChunbo
 * @create 2020-03-11 8:51
 * @Description: 类的描述
 */
@SpringCloudApplication
@EnableFeignClients(clients = {OrderService.class}) //开启并指定加载
public class FeginUserApplication {

    public static void main(String[] args) {
        SpringApplication.run(FeginUserApplication.class,args);
    }

    /**
     * 注入RestTemplate 用于调用服务
     * @return
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    //手动设置负载均衡策略
    @Bean
    public IRule iRule(){
        //默认轮询 RoundRobinRule
        //随机 RandomRule
        //重试 RetryRule
        //空闲 BestAvailableRule
        return  new BestAvailableRule();
    }
}
